<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
<title>Sbeam后台管理端</title>
<%@ include file="../common/dev_head.jsp"%>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
	$("#mainmenu li").removeClass("active-menu");
	$("#mainmenu>li").eq(2).addClass("active-menu");
});

//删除用户
function deleteUser(userid){
	if(confirm("你确定要删除当前用户？该操作不可撤销！")){
		$.ajax({
			url:getContextPath()+"/admin/deleteadmin",
			type:"POST",
			data:{userId:userid},
			success:function(result){
				if(result=="1"){
					alert("删除成功！");
					window.location.href=getContextPath()+"/admin/aduitormanager";
				}else{
					alert("删除失败！请稍后重试！");
				}
			}
		});	
	}	
}

//添加审核者
function addSave(){
	var name=$("#add_name").val();
	var pass=$("#add_pass").val();
	$.ajax({
		url:getContextPath()+"/admin/addadmin",
		type:"POST",
		data:{adminName:name,adminPass:pass},
		success:function(result){
			if(result=="1"){
				alert("添加成功！");
				window.location.href=getContextPath()+"/admin/aduitormanager";
			}else{
				alert("添加失败请稍后重试！");		
			}
		}
	});
	
}


//为模态框赋值
function setValue(userid){
	$("#modal_uid").val(userid);
}


</script>



	<div id="wrapper">
		
		<%@ include file="./admin_title.jsp" %>
		<div id="page-wrapper">
			<div id="page-inner">
				<div class="row">
					<div class="col-md-12">
						<h1 class="page-header">审核者列表</h1>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-12">
						<div class="panel panel-default">
							<div class="panel-heading">
								<a href="#"  data-toggle="modal" data-target="#ModalAdd" class="btn btn-primary">添加审核者</a>
							</div>
							<div class="panel-body">
								<c:if test="${!empty user }">
									<div class="table-responsive">
									<table class="table table-striped table-bordered table-hover"
										id="dataTables-example" style="text-align:center;">
										<thead>
											<tr>
												<th>审核者id</th>
												<th>用户名</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
											<c:forEach items="${user }" var="p">
												<tr class="odd gradeX">
												<td style="width:100px;">${p.adminId }</td>
												<td style="width:200px;"><span>${p.adminName }</span></td>
												<td style="width:100px;" class="center">
													<div style="margin-top:10px">
														<a href="javascript:void(0)" onclick="deleteUser(${p.adminId })">
															<span class="glyphicon glyphicon-remove">&thinsp;删除</span>
														</a>
														&thinsp;
														&thinsp;
														<a href="#"
															data-toggle="modal" data-target="#myModal" onClick="setValue(${p.adminId})">
															<span class="glyphicon glyphicon-edit">&thinsp;修改</span>
														</a>
													</div>
												</td>
											</tr>
											</c:forEach>
										</tbody>
									</table>
								</div>
								<!--Modal -->
									<div class="modal fade" id="myModal" tabindex="-1"
										role="dialog" aria-labelledby="myModalLabel"
										aria-hidden="true">
										<div class="modal-dialog">
											<div class="modal-content">
												<div class="modal-header">
													<button type="button" class="close" data-dismiss="modal"
														aria-hidden="true">&times;</button>
													<h4 class="modal-title" id="myModalLabel">审核者信息</h4>
												</div>
												<div class="modal-body">
													<div class="row">
														<div class="col-lg-12">
															<form role="form" enctype="multipart/form-data" id="modal_game">
																<input type="hidden" id="modal_uid" name="modal_uid">
																<div class="form-group">
																	
																	<label>审核者名称</label> 
																	<input type="text" id="modal_name" name="modal_name"
																		class="form-control"> 
																	<label>审核者密码</label> 
																	<input type="text" id="modal_pass" name="modal_pass"
																		class="form-control"> 
																</div>
															</form>
														</div>
													</div>
												</div>
												<div class="modal-footer">
													<button type="button" class="btn btn-default"
														data-dismiss="modal">关闭</button>
													<button type="button" class="btn btn-primary" onClick="save()">保存设置</button>
												</div>
											</div>
										</div>
									</div>
									<script>
									//在模态框显示之前为模态框内元素赋值
									$('#myModal').on('show.bs.modal', function() {
										var uid=$("#modal_uid").val();
										$.ajax({
											url:getContextPath()+"/admin/findAdminById",
											data:{uid:uid},
											type:"POST",
											success:function(admin){
												$("#modal_name").attr("value",admin.adminName);
												$("#modal_pass").attr("value",admin.adminPass);
											}
										});
									})
									
									function save(){
										var id=$("#modal_uid").val();
										var name=$("#modal_name").val();
										var pass=$("#modal_pass").val();
										$.ajax({
											url:getContextPath()+"/admin/adminupdate",
											type:"POST",
											data:{adminId:id,adminName:name,adminPass:pass},
											success:function(result){
												switch(result){
												case "1":
													alert("修改成功!");
													window.location.href=getContextPath()+"/admin/aduitormanager";
													break;
												case "2":
													alert("更新用户信息失败,请稍后重试!");
													break;
												}
											}
										});
									}
									
									</script>
									
									<div class="modal fade" id="ModalAdd" tabindex="-1"
										role="dialog" aria-labelledby="ModalAdd"
										aria-hidden="true">
										<div class="modal-dialog">
											<div class="modal-content">
												<div class="modal-header">
													<button type="button" class="close" data-dismiss="modal"
														aria-hidden="true">&times;</button>
													<h4 class="modal-title" id="myModalLabel">审核者信息</h4>
												</div>
												<div class="modal-body">
													<div class="row">
														<div class="col-lg-12">
															<form role="form" enctype="multipart/form-data" id="modal_game">
																<div class="form-group">
																	
																	<label>审核者名称</label> 
																	<input type="text" id="add_name" name="add_name"
																		class="form-control"> 
																	<label>审核者密码</label> 
																	<input type="text" id="add_pass" name="add_pass"
																		class="form-control"> 
																</div>
															</form>
														</div>
													</div>
												</div>
												<div class="modal-footer">
													<button type="button" class="btn btn-default"
														data-dismiss="modal">关闭</button>
													<button type="button" class="btn btn-primary" onClick="addSave()">保存设置</button>
												</div>
											</div>
										</div>
									</div>
									
								
								
								<!-- EndModal -->
								
								
								</c:if>
							</div>
							
						</div>
					</div>
					<!-- /. PAGE INNER  -->
				</div>
				<!-- /. PAGE WRAPPER  -->
			</div>
		</div>
		
		<!-- /. PAGE WRAPPER  -->
	</div>
	<!-- /. WRAPPER  -->
	
</body>
</html>